/* The file is saved in UTF-8 codepage.
 * Check: «Stereotype», Section mark-§, Copyright-©, Alpha-α, Beta-β, Smile-☺
 */
package cz.pecinovsky.english.lootp._125_;


import cz.pecinovsky.english.lootp._000_.Run;

import cz.pecinovsky.english.lootp.manager.Mover;


import cz.pecinovsky.english.lootp.manager.CanvasManager_Envelope.               CanvasManager;
import cz.pecinovsky.english.lootp._125_.TrafficLight_125_133.                   TrafficLight;
import cz.pecinovsky.english.lootp._125_.TestUtility_129_133.                    TestUtility;


////////////////////////////////////////////////////////////////////////////////
//%%+  +++++ End of ignored starting test - place for imports +++++
//%I+ =133c
//
//import správce.*;
//%I-
//%I+ >=133z
//
//import cz.pecinovsky.english.lootp.canvasmanager.Mover;
//import cz.pecinovsky.english.lootp.canvasmanager.CanvasManager;
//%I-
//%A+ >=133z

import cz.pecinovsky.english.lootp.utility.NamedColor;
import cz.pecinovsky.english.lootp.utility.IO;
import cz.pecinovsky.english.lootp.utility.Position;
//%A-
//%X+ xxxxx Start of the ovejumped text with declaration of the envelope xxxxx
/*******************************************************************************
 *<pre>
 * Předchozí:   Není - toto_je_nově_definovaná_třída
 *              Ttt v projektu Ppp
 * Následující: Prozatím není
 *
 * Projekt  Ppp
 *   + Přidáno
 *   - Odebráno
 *   ~ Změněno
 *</pre>
 */
public class TrafficLightTest_125_133
{    private TrafficLightTest_125_133() {}   static
////////////////////////////////////////////////////////////////////////////////
//%X- ----- End of the ovejumped text with declaration of the envelope -----


/*******************************************************************************
 * Testovací třída {@code TrafficLightTest}  slouží ke komplexnímu otestování
 * třídy {@link TrafficLightTest}.
 *
 * @author Rudolf PECINOVSKÝ
 * @version 6.03.2017 — 2010-11-08
 */
public class TrafficLightTest extends junit.framework.TestCase
{
    private CanvasManager CM;
    private TrafficLight trafficLight0;
    private TrafficLight trafficLightXY;
    private TrafficLight trafficLightXYB;
    private TrafficLight trafficLightXYM;
    private TrafficLight trafficLightXYMB;



//== CONSTANT CLASS ATTRIBUTES =================================================
//== VARIABLE CLASS ATTRIBUTES =================================================
//== STATIC CONSTRUCTOR (CLASS INITIALIZER, STATIC INICITALIZING BLOCK) ========
//== CONSTANT INSTANCE ATTRIBUTES ==============================================
//== VARIABLE INSTANCE ATTRIBUTES ==============================================
//== CLASS GETTERS AND SETTERS =================================================
//== OTHER NON-PRIVATE CLASS METHODS ===========================================

//##############################################################################
//== CONSTUCTORS AND FACTORY METHODS ===========================================

    /***************************************************************************
     * Vytvoří test se zadaným názvem.
     *
     * @param name  Název konstruovaného testu
     */
    public TrafficLightTest(String name)
    {
        super(name);
    }



//== PREPARATION AND CLEANING THE FIXTURE ======================================

    /***************************************************************************
     * Inicializace předcházející spuštění každého testu a připravující tzv.
     * přípravek (fixture), což je sada objektů, s nimiž budou testy pracovat.
     */
    @Override
    protected void setUp()
    {
        trafficLight0   = new TrafficLight();
        trafficLightXY  = new TrafficLight(100,  50);
        trafficLightXYB = new TrafficLight(150, 100, NamedColor.BROWN);
        trafficLightXYM = new TrafficLight(75,  25, 25);
        trafficLightXYMB= new TrafficLight(200,   0, 100, NamedColor.BLUE);

        CM = CanvasManager.getInstance();
        CM.add(trafficLight0);
        CM.add(trafficLightXY);
        CM.add(trafficLightXYB);
        CM.add(trafficLightXYM);
        CM.add(trafficLightXYMB);

//%X+ <126
        System.out.println("\n====== Instance v přípravku pro " + this +
                           "\n| CM: " + CM +
                           "\n| trafficLight0:    " + trafficLight0 +
                           "\n| trafficLightXY:   " + trafficLightXY +
                           "\n| trafficLightXYB:  " + trafficLightXYB +
                           "\n| trafficLightXYM : " + trafficLightXYM +
                           "\n| trafficLightXYMB: " + trafficLightXYMB +
                           "\n======");
//%X-
        IO.inform("Traffic lights prepared");
    }


    /***************************************************************************
     * Úklid po testu - tato metoda se spustí po vykonání každého testu.
     */
    @Override
    protected void tearDown()
    {
    }


//== PRIVATE AND AUXILIARY CLASS METHODS =======================================
//== PRIVATE AND AUXILIARY INSTANCE METHODS ====================================
//%I+ <129
//
//    /***************************************************************************
//     * Za pomoci přesouvače plynule prohodí pozice zadaných trafficLightů.
//     *
//     * @param s1 První trafficLight
//     * @param s2 Druhý trafficLight
//     */
//    private void auxSmoothlySwapPositions(TrafficLight s1, TrafficLight s2)
//    {
//        Mover mover = new Mover(10);
//        Position p1 = s1.getPosition();
//        mover.moveTo(s2.getPosition(), s1);
//        mover.moveTo(p1,             s2);
//    }
//
//
//    /***************************************************************************
//     * Vyzkouší změny pozice a velikosti zadaného trafficLightu.
//     *
//     * @param s Testovaný trafficLight
//     */
//    private void auxPositionSize(TrafficLight s)
//    {
//        final int ms = 500;
//        s.setPosition(50, 0);
//        IO.pause(ms);
//        s.setModule(100);
//        IO.pause(ms);
//        s.setModule(25);
//        IO.pause(ms);
//        CM.remove(s);
//        IO.pause(ms);
//    }
//
//%I-
//%I+ >127 <129
//
//    /***************************************************************************
//     * Prohodí pozice zadaných trafficLightů a nechá zkontrolovat,
//     * zda si trafficLighty své pozice doopravdy vyměnily.
//     *
//     * @param s1 První trafficLight
//     * @param s2 Druhý trafficLight
//     */
//    private void auxSwapPositionsWithCheck(TrafficLight s1, TrafficLight s2)
//    {
//        Position p1 = s1.getPosition();
//        Position p2 = s2.getPosition();
//
//        System.out.println("Výchozí: " + p1 + " <--> " + p2);
//        auxSmoothlySwapPositions(s1, s2);
//        System.out.println("Cílová:  " + s1.getPosition() +
//                              " <--> " + s2.getPosition() + "\n");
//
//        assertEquals(p1, s2.getPosition());
//        assertEquals(p2, s1.getPosition());
//    }
//
//%I-


//== EMBEDDED TYPES AND INNER CLASSES ==========================================
//== THE TESTS =================================================================
//
//     /***************************************************************************
//      *
//      */
//     public void testXXX()
//     {
//     }


    public void testCycle()
    {
        trafficLight0   .cycle();
        trafficLightXY  .cycle();
        trafficLightXYB .cycle();
        trafficLightXYM .cycle();
        trafficLightXYMB.cycle();
    }


    public void testSmoothMovement()
    {
        Mover p = new Mover(10);
        p.moveTo(100, 150, trafficLight0);
        p.moveTo(150,   0, trafficLightXY);
        p.moveTo(100,   0, trafficLightXYB);
        p.moveTo(150, 150, trafficLightXYM);
        p.moveTo( 0,   0, trafficLightXYMB);
    }

//%I+ <129
//
//    public void testSmoothlySwapPositions()
//    {
//        auxSmoothlySwapPositions(trafficLightXYMB, trafficLight0);
//        auxSmoothlySwapPositions(trafficLightXYB,  trafficLightXYM);
//    }
//
//%I-

    public void testPositionSize()
    {
//%I+ <129
//        auxPositionSize(trafficLight0);
//        auxPositionSize(trafficLightXY);
//        auxPositionSize(trafficLightXYB);
//        auxPositionSize(trafficLightXYM);
//        auxPositionSize(trafficLightXYMB);
//%I-
//%X+ <129
        TestUtility.setPoziceModuly(new Position(50, 0), 25, 100);
        TestUtility.positionSize(trafficLight0);
        TestUtility.positionSize(trafficLightXY);
        TestUtility.positionSize(trafficLightXYB);
        TestUtility.positionSize(trafficLightXYM);
        TestUtility.positionSize(trafficLightXYMB);
//%X-
    }
//%X+ <127


    public void testSwapPositionsWithCheck()
    {
//%X-
//%I+ >127 <129
//        auxSwapPositionsWithCheck(trafficLight0,   trafficLightXYMB);
//        auxSwapPositionsWithCheck(trafficLightXYB, trafficLightXYM);
//        auxSwapPositionsWithCheck(trafficLightXYM, trafficLight0);
//%I-
//%X+ <129
        TestUtility.swapPositionsWithCheck(trafficLight0,   trafficLightXYMB);
        TestUtility.swapPositionsWithCheck(trafficLightXYB, trafficLightXYM);
        TestUtility.swapPositionsWithCheck(trafficLightXYM, trafficLight0);
//%X-
//%X+ <127
    }
//%X-
//%X+
     /** */
     public void testFixture() {}
//%X-
}

//%%- ---- Start of the ovejumped text with closing of the envelope ----
////////////////////////////////////////////////////////////////////////////////
//== TESTING CLASSES AND METHODS ===============================================
//Není-li třída testovací, následující dvě metody se smažou


    /***************************************************************************
     * Třída, jejíž instance má na starosti úklid mezi jednotlivými testy,
     * který není možno zakomponovat do metody {@code tearDown()},
     * dokud nebudou studenti umět programovat.
     */
    private static class TearDown implements Run.ITD
    {
        /** {@inheritDoc} */
        @Override
        public void cleanUp()
        {
//            Canvas.clearCanvas();
//            CanvasManager.getInstance().removeAll();
        }
    }


    /***************************************************************************
     * Test method.
     */
    public static void test()
    {
        Run.tests(TrafficLightTest.class,
                new TearDown(),
//                "testFixture",
//                "testCycle",
                "testPositionSize",
//                "testSmoothMovement",
//                "testSmoothlySwapPositions",
                "testSwapPositionsWithCheck",
                "");
        System.exit(0);
    }
    /** @param args Parametry příkazového řádku - nepoužívané. */
    public static void main(String[] args)  {  test();  }
}
